// 统一的出口
import Request from './request'
import { Toast } from 'vant'
import { getItem } from '@/utils/storage'

const BASE_URL = import.meta.env.VITE_APP_BASE_API as string
const request = new Request({
  baseURL: BASE_URL,
  timeout: 4 * 1000,
  interceptors: {
    requestInterceptor: (config: any) => {
      // 携带token的拦截
      const token = getItem('token')
      if (token) {
        config.headers.Authorization = `Bearer ${token}`
      }
      return config
    },
    requestInterceptorCatch: (err) => {
      return err
    }
    // respenseInterceptor: (res) => {
    //   return res
    // },
    // respenseInterceptorCatch: (err) => {
    //   Toast.fail('请求错误')
    //   return err
    // }
  }
})
export default request
